home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / advn4d44 / game.fr_ / game.fr (.txt)
Encoding:
Visual Basic Form  |  1997-02-11  |  34.5 KB  |  1,044 lines

  1. VERSION 4.00
  2. Begin VB.Form frmGame 
  3.    ClientHeight    =   4164
  4.    ClientLeft      =   -72
  5.    ClientTop       =   1752
  6.    ClientWidth     =   7488
  7.    ControlBox      =   0   'False
  8.    Height          =   4548
  9.    Left            =   -120
  10.    LinkTopic       =   "Form1"
  11.    MDIChild        =   -1  'True
  12.    ScaleHeight     =   4164
  13.    ScaleWidth      =   7488
  14.    Top             =   1416
  15.    Visible         =   0   'False
  16.    Width           =   7584
  17.    WindowState     =   2  'Maximized
  18.    Begin VB.CommandButton pbDrop 
  19.       Caption         =   "Drop"
  20.       Height          =   300
  21.       Left            =   6048
  22.       TabIndex        =   30
  23.       Top             =   3456
  24.       Width           =   972
  25.    End
  26.    Begin VB.CommandButton pbWayOut 
  27.       Caption         =   "WayOut"
  28.       Height          =   300
  29.       Left            =   4704
  30.       TabIndex        =   29
  31.       Top             =   3648
  32.       Width           =   972
  33.    End
  34.    Begin VB.CommandButton pbCarry 
  35.       Caption         =   "Carry"
  36.       Height          =   300
  37.       Left            =   3456
  38.       TabIndex        =   28
  39.       Top             =   3456
  40.       Width           =   972
  41.    End
  42.    Begin VB.CommandButton pbBackward 
  43.       Caption         =   "Backward"
  44.       Height          =   204
  45.       Left            =   5760
  46.       TabIndex        =   27
  47.       Top             =   2976
  48.       Width           =   972
  49.    End
  50.    Begin VB.CommandButton pbDown 
  51.       Caption         =   "Down"
  52.       Height          =   204
  53.       Left            =   3648
  54.       TabIndex        =   26
  55.       Top             =   2976
  56.       Width           =   972
  57.    End
  58.    Begin VB.CommandButton pbSouth 
  59.       Caption         =   "Sourth"
  60.       Height          =   204
  61.       Left            =   4704
  62.       TabIndex        =   25
  63.       Top             =   2784
  64.       Width           =   972
  65.    End
  66.    Begin VB.CommandButton pbEast 
  67.       Caption         =   "East"
  68.       Height          =   204
  69.       Left            =   5760
  70.       TabIndex        =   24
  71.       Top             =   2592
  72.       Width           =   972
  73.    End
  74.    Begin VB.CommandButton pbWest 
  75.       Caption         =   "West"
  76.       Height          =   204
  77.       Left            =   3648
  78.       TabIndex        =   23
  79.       Top             =   2592
  80.       Width           =   972
  81.    End
  82.    Begin VB.CommandButton pbUp 
  83.       Caption         =   "Up"
  84.       Height          =   204
  85.       Left            =   5760
  86.       TabIndex        =   22
  87.       Top             =   2208
  88.       Width           =   972
  89.    End
  90.    Begin VB.CommandButton pbNorth 
  91.       Caption         =   "North"
  92.       Height          =   204
  93.       Left            =   4704
  94.       TabIndex        =   21
  95.       Top             =   2400
  96.       Width           =   972
  97.    End
  98.    Begin VB.CommandButton pbForward 
  99.       Caption         =   "Forward"
  100.       Height          =   204
  101.       Left            =   3648
  102.       TabIndex        =   20
  103.       Top             =   2208
  104.       Width           =   972
  105.    End
  106.    Begin VB.TextBox txtMaxScore 
  107.       Enabled         =   0   'False
  108.       Height          =   288
  109.       Left            =   6240
  110.       TabIndex        =   17
  111.       Text            =   "100"
  112.       Top             =   1632
  113.       Width           =   588
  114.    End
  115.    Begin VB.TextBox txtNumTreasures 
  116.       Enabled         =   0   'False
  117.       Height          =   288
  118.       Left            =   6240
  119.       TabIndex        =   16
  120.       Text            =   "15"
  121.       Top             =   1248
  122.       Width           =   588
  123.    End
  124.    Begin VB.TextBox txtNumRooms 
  125.       Enabled         =   0   'False
  126.       Height          =   288
  127.       Left            =   6240
  128.       TabIndex        =   15
  129.       Text            =   "100"
  130.       Top             =   864
  131.       Width           =   588
  132.    End
  133.    Begin VB.TextBox txtScore 
  134.       Enabled         =   0   'False
  135.       Height          =   288
  136.       Left            =   5184
  137.       TabIndex        =   13
  138.       Text            =   "0"
  139.       Top             =   1632
  140.       Width           =   588
  141.    End
  142.    Begin VB.TextBox txtTreasuresRecovered 
  143.       Enabled         =   0   'False
  144.       Height          =   288
  145.       Left            =   5184
  146.       TabIndex        =   12
  147.       Text            =   "0"
  148.       Top             =   1248
  149.       Width           =   588
  150.    End
  151.    Begin VB.TextBox txtRoomsVisited 
  152.       Enabled         =   0   'False
  153.       Height          =   288
  154.       Left            =   5184
  155.       TabIndex        =   11
  156.       Text            =   "1"
  157.       Top             =   864
  158.       Width           =   588
  159.    End
  160.    Begin VB.TextBox txtMoves 
  161.       Enabled         =   0   'False
  162.       Height          =   288
  163.       Left            =   5184
  164.       TabIndex        =   10
  165.       Text            =   "0"
  166.       Top             =   480
  167.       Width           =   588
  168.    End
  169.    Begin VB.CommandButton pbAbout 
  170.       Caption         =   "About"
  171.       Height          =   252
  172.       Left            =   6144
  173.       TabIndex        =   5
  174.       Top             =   288
  175.       Width           =   972
  176.    End
  177.    Begin VB.ListBox lstInventory 
  178.       Height          =   1200
  179.       Left            =   120
  180.       TabIndex        =   3
  181.       Top             =   2760
  182.       Width           =   2652
  183.    End
  184.    Begin VB.TextBox txtLocation 
  185.       Height          =   1452
  186.       Left            =   120
  187.       MultiLine       =   -1  'True
  188.       ScrollBars      =   2  'Vertical
  189.       TabIndex        =   0
  190.       Top             =   840
  191.       Width           =   2652
  192.    End
  193.    Begin VB.Label Label10 
  194.       Caption         =   "of"
  195.       Height          =   204
  196.       Left            =   5952
  197.       TabIndex        =   19
  198.       Top             =   1728
  199.       Width           =   204
  200.    End
  201.    Begin VB.Label Label9 
  202.       Caption         =   "of"
  203.       Height          =   204
  204.       Left            =   5952
  205.       TabIndex        =   18
  206.       Top             =   1344
  207.       Width           =   204
  208.    End
  209.    Begin VB.Label Label8 
  210.       Caption         =   "of"
  211.       Height          =   204
  212.       Left            =   5952
  213.       TabIndex        =   14
  214.       Top             =   960
  215.       Width           =   204
  216.    End
  217.    Begin VB.Label Label7 
  218.       Alignment       =   1  'Right Justify
  219.       Caption         =   "Score"
  220.       Height          =   180
  221.       Left            =   4416
  222.       TabIndex        =   9
  223.       Top             =   1728
  224.       Width           =   612
  225.    End
  226.    Begin VB.Label Label6 
  227.       Alignment       =   1  'Right Justify
  228.       Caption         =   "Treasures recovered"
  229.       Height          =   180
  230.       Left            =   3360
  231.       TabIndex        =   8
  232.       Top             =   1344
  233.       Width           =   1668
  234.    End
  235.    Begin VB.Label Label5 
  236.       Alignment       =   1  'Right Justify
  237.       Caption         =   "Rooms visited"
  238.       Height          =   180
  239.       Left            =   3840
  240.       TabIndex        =   7
  241.       Top             =   960
  242.       Width           =   1188
  243.    End
  244.    Begin VB.Label Label4 
  245.       Alignment       =   1  'Right Justify
  246.       Caption         =   "Moves"
  247.       Height          =   180
  248.       Left            =   4416
  249.       TabIndex        =   6
  250.       Top             =   600
  251.       Width           =   636
  252.    End
  253.    Begin VB.Label Label3 
  254.       Caption         =   "Inventory"
  255.       Height          =   252
  256.       Left            =   120
  257.       TabIndex        =   4
  258.       Top             =   2400
  259.       Width           =   2052
  260.    End
  261.    Begin VB.Label Label2 
  262.       Caption         =   "Location"
  263.       Height          =   252
  264.       Left            =   120
  265.       TabIndex        =   2
  266.       Top             =   480
  267.       Width           =   732
  268.    End
  269.    Begin VB.Label Label1 
  270.       Alignment       =   2  'Center
  271.       Caption         =   "Visit all of the rooms and return all of the treasures to the entrance."
  272.       Height          =   252
  273.       Left            =   120
  274.       TabIndex        =   1
  275.       Top             =   120
  276.       Width           =   4812
  277.    End
  278. Attribute VB_Name = "frmGame"
  279. Attribute VB_Creatable = False
  280. Attribute VB_Exposed = False
  281. Option Explicit
  282. Public bEuclidean As Boolean
  283. Public nDimensions As Long
  284. Public nGame As Long
  285. Private bConnected() As Boolean
  286. Private bDirectionFound As Boolean
  287. Private bDirectionUsed(255, 4, 2) As Boolean
  288. Private bInitialized As Boolean
  289. Private bPathFound As Boolean
  290. Private bRoomUsed() As Boolean
  291. Private bTreasureCarried As Boolean
  292. Private bVisited() As Boolean
  293. Private bWeaponRoomFound As Boolean
  294. Private bWidthsFound As Boolean
  295. Private dblScore As Double
  296. Private nCell(15, 15, 15, 15) As Long
  297. Private nCoordinate(4) As Long
  298. Private nCoordinateNext(4) As Long
  299. Private nDimension1 As Long
  300. Private nDimension2 As Long
  301. Private nDirection1 As Long
  302. Private nDirection2 As Long
  303. Private nDirectionsPossible As Long
  304. Private nDirectionsUsed(255) As Long
  305. Private nGuardRoom() As Long
  306. Private nMaxWidth As Long
  307. Private nMoves As Long
  308. Private nRoom1 As Long
  309. Private nRoom2 As Long
  310. Private nRooms As Long
  311. Private nScore As Long
  312. Private nTCoordinate As Long
  313. Private nTreasure1 As Long
  314. Private nTreasure2 As Long
  315. Private nTreasureRoom() As Long
  316. Private nTreasures As Long
  317. Private nTreasuresCarried As Long
  318. Private nTreasuresRecovered As Long
  319. Private nTrial As Long
  320. Private nVisited As Long
  321. Private nVolume As Long
  322. Private nWayOutDimension(255) As Long
  323. Private nWayOutDirection(255) As Long
  324. Private nWayOutHead As Long
  325. Private nWayOutPtr As Long
  326. Private nWeaponRoom() As Long
  327. Private nWidth(4) As Long
  328. Private nXCoordinate As Long
  329. Private nYCoordinate As Long
  330. Private nZCoordinate As Long
  331. Private strDescription() As String
  332. Private strGuard() As String
  333. Private strLine As String
  334. Private strTreasure() As String
  335. Private strTreasures As String
  336. Private strWayOut As String
  337. Private strWeapon() As String
  338. Private Declare Function GetModuleFileName Lib "KERNEL32" Alias "GetModuleFileNameA" (ByVal hModule As Long, ByVal strFileName As String, ByVal nFileNameLength As Long) As Long
  339. Private Function GetProgramPath() As String
  340.   Dim nCharIndex As Long
  341.   Dim nFileNameLength As Long
  342.   Dim nLastSlash As Long
  343.   Dim nModuleHandle As Long
  344.   Dim strFileName As String
  345.   Dim strResult As String
  346.   strResult = "C:\VB\TREASURE\" 'For development
  347.   nModuleHandle = 0
  348.   nFileNameLength = 256
  349.   strFileName = String(nFileNameLength, 0)
  350.   nFileNameLength = GetModuleFileName(nModuleHandle, strFileName, nFileNameLength)
  351.   If nFileNameLength > 0 Then
  352.     nLastSlash = 0
  353.     For nCharIndex = 1 To nFileNameLength
  354.       If Mid(strFileName, nCharIndex, 1) = "\" Then
  355.         nLastSlash = nCharIndex
  356.       End If
  357.     Next nCharIndex
  358.     If nLastSlash > 0 Then
  359.       If Mid(strFileName, nLastSlash + 1, nFileNameLength - nLastSlash) <> "VB32.EXE" Then
  360.         strResult = Left(strFileName, nLastSlash)
  361.       End If
  362.     End If
  363.   End If
  364.   GetProgramPath = strResult
  365. End Function
  366. Private Sub GameUpdate()
  367.   Dim Response As Long
  368.   txtMoves.Text = nMoves
  369.   If (Not bEuclidean) Then
  370.     If nXCoordinate < 0 Then
  371.       nYCoordinate = nWidth(1) - 1 - nYCoordinate
  372.       nZCoordinate = nWidth(2) - 1 - nZCoordinate
  373.       nTCoordinate = nWidth(3) - 1 - nTCoordinate
  374.       nXCoordinate = nWidth(0) - 1
  375.     Else
  376.       If nXCoordinate >= nWidth(0) Then
  377.         nYCoordinate = nWidth(1) - 1 - nYCoordinate
  378.         nZCoordinate = nWidth(2) - 1 - nZCoordinate
  379.         nTCoordinate = nWidth(3) - 1 - nTCoordinate
  380.         nXCoordinate = 0
  381.       End If
  382.     End If
  383.     If nYCoordinate < 0 Then
  384.       nXCoordinate = nWidth(0) - 1 - nXCoordinate
  385.       nZCoordinate = nWidth(2) - 1 - nZCoordinate
  386.       nTCoordinate = nWidth(3) - 1 - nTCoordinate
  387.       nYCoordinate = nWidth(1) - 1
  388.     Else
  389.       If nYCoordinate >= nWidth(1) Then
  390.         nXCoordinate = nWidth(0) - 1 - nXCoordinate
  391.         nZCoordinate = nWidth(2) - 1 - nZCoordinate
  392.         nTCoordinate = nWidth(3) - 1 - nTCoordinate
  393.         nYCoordinate = 0
  394.       End If
  395.     End If
  396.     If nZCoordinate < 0 Then
  397.       nXCoordinate = nWidth(0) - 1 - nXCoordinate
  398.       nYCoordinate = nWidth(1) - 1 - nYCoordinate
  399.       nTCoordinate = nWidth(3) - 1 - nTCoordinate
  400.       nZCoordinate = nWidth(2) - 1
  401.     Else
  402.       If nZCoordinate >= nWidth(2) Then
  403.         nXCoordinate = nWidth(0) - 1 - nXCoordinate
  404.         nYCoordinate = nWidth(1) - 1 - nYCoordinate
  405.         nTCoordinate = nWidth(3) - 1 - nTCoordinate
  406.         nZCoordinate = 0
  407.       End If
  408.     End If
  409.     If nTCoordinate < 0 Then
  410.       nXCoordinate = nWidth(0) - 1 - nXCoordinate
  411.       nYCoordinate = nWidth(1) - 1 - nYCoordinate
  412.       nZCoordinate = nWidth(2) - 1 - nZCoordinate
  413.       nTCoordinate = nWidth(3) - 1
  414.     Else
  415.       If nTCoordinate >= nWidth(3) Then
  416.         nXCoordinate = nWidth(0) - 1 - nXCoordinate
  417.         nYCoordinate = nWidth(1) - 1 - nYCoordinate
  418.         nZCoordinate = nWidth(2) - 1 - nZCoordinate
  419.         nTCoordinate = 0
  420.       End If
  421.     End If
  422.   End If
  423.   nRoom1 = nCell(nXCoordinate, nYCoordinate, nZCoordinate, nTCoordinate)
  424.   If ((nRoom1 <> 0) And (strWayOut = "") And (Int(100# * Rnd) = 0)) Then
  425.     nRoom2 = 0
  426.     Do While nRoom2 <= 0
  427.       nXCoordinate = Int(CDbl(nWidth(0)) * Rnd)
  428.       nYCoordinate = Int(CDbl(nWidth(1)) * Rnd)
  429.       nZCoordinate = Int(CDbl(nWidth(2)) * Rnd)
  430.       nTCoordinate = Int(CDbl(nWidth(3)) * Rnd)
  431.       nRoom2 = nCell(nXCoordinate, nYCoordinate, nZCoordinate, nTCoordinate)
  432.     Loop
  433.     If nRoom2 <> nRoom1 Then
  434.       nRoom1 = nRoom2
  435.       Response = MsgBox("A flock of bats grabs you,  flies you through the caverns,  and drops you.", vbOKOnly, "Yeowwww!")
  436.     End If
  437.   End If
  438.   strWayOut = ""
  439.   nTreasuresRecovered = 0
  440.   nTreasure1 = 0
  441.   bTreasureCarried = False
  442.   Do While (nTreasure1 < nTreasures) And (Not bTreasureCarried)
  443.     If nTreasureRoom(nTreasure1) < 0 Then
  444.       bTreasureCarried = True
  445.     Else
  446.       nTreasure1 = nTreasure1 + 1
  447.     End If
  448.   Loop
  449.   If bTreasureCarried Then
  450.     If Int(CDbl(2 * nRooms) * Rnd) = 0 Then
  451.       nRoom2 = 0
  452.       Do While nRoom2 <= 0
  453.         nDimension1 = 0
  454.         Do While nDimension1 < nDimensions
  455.           nCoordinate(nDimension1) = Int(CDbl(nWidth(nDimension1)) * Rnd)
  456.           nDimension1 = nDimension1 + 1
  457.         Loop
  458.         nRoom2 = nCell(nCoordinate(0), nCoordinate(1), nCoordinate(2), nCoordinate(3))
  459.         If nRoom1 = nRoom2 Then
  460.           nRoom2 = -1
  461.         End If
  462.       Loop
  463.       nTreasure1 = 0
  464.       Do While nTreasure1 < nTreasures
  465.         If nTreasureRoom(nTreasure1) < 0 Then
  466.           nTreasureRoom(nTreasure1) = nRoom2
  467.         End If
  468.         nTreasure1 = nTreasure1 + 1
  469.       Loop
  470.       bTreasureCarried = False
  471.       Response = MsgBox("As he leaves,  he says,  'Arggh!  I'll hide me booty better this time.'", vbOKOnly, "A pirate jumps out of the shadows and takes your treasure.")
  472.     End If
  473.   End If
  474.   nTreasure1 = 0
  475.   nTreasure2 = 0
  476.   strTreasures = ""
  477.   lstInventory.Clear
  478.   nTreasuresCarried = 0
  479.   Do While nTreasure1 < nTreasures
  480.     If nTreasureRoom(nTreasure1) = 0 Then
  481.       nTreasuresRecovered = nTreasuresRecovered + 1
  482.       If nRoom1 = 0 Then
  483.         strTreasures = strTreasures & "  There's " & strTreasure(nTreasure1) & " here. "
  484.       End If
  485.     Else
  486.       If nTreasureRoom(nTreasure1) = nRoom1 Then
  487.         strTreasures = strTreasures & "  There's " & strTreasure(nTreasure1) & " here. "
  488.         If nGuardRoom(nTreasure1) = nRoom1 Then
  489.           strLine = Left(strGuard(nTreasure1), 1)
  490.           If ((strLine = "a") Or (strLine = "e") Or (strLine = "i") Or (strLine = "o") Or (strLine = "u")) Then
  491.             strTreasures = strTreasures & "  It's guarded by an " & strGuard(nTreasure1) & "."
  492.           Else
  493.             strTreasures = strTreasures & "  It's guarded by a " & strGuard(nTreasure1) & "."
  494.           End If
  495.         End If
  496.       Else
  497.         If nTreasureRoom(nTreasure1) = -1 Then
  498.           bTreasureCarried = True
  499.           nTreasuresCarried = nTreasuresCarried + 1
  500.           nTreasure2 = nTreasure2 + 1
  501.           lstInventory.AddItem strTreasure(nTreasure1)
  502.         End If
  503.       End If
  504.     End If
  505.     If nWeaponRoom(nTreasure1) = nRoom1 Then
  506.       strLine = Left(strWeapon(nTreasure1), 1)
  507.       If ((strLine = "a") Or (strLine = "e") Or (strLine = "i") Or (strLine = "o") Or (strLine = "u")) Then
  508.         strTreasures = strTreasures & " There's an " & strWeapon(nTreasure1) & " here."
  509.       Else
  510.         strTreasures = strTreasures & " There's a " & strWeapon(nTreasure1) & " here."
  511.       End If
  512.     Else
  513.       If nWeaponRoom(nTreasure1) = -1 Then
  514.         nTreasure2 = nTreasure2 + 1
  515.         lstInventory.AddItem strWeapon(nTreasure1)
  516.       End If
  517.     End If
  518.     nTreasure1 = nTreasure1 + 1
  519.   Loop
  520.   txtTreasuresRecovered.Text = nTreasuresRecovered
  521.   txtNumTreasures.Text = nTreasures
  522.   If (Not bVisited(nRoom1)) Then
  523.     nVisited = nVisited + 1
  524.     bVisited(nRoom1) = True
  525.   End If
  526.   txtRoomsVisited.Text = nVisited
  527.   txtNumRooms.Text = nRooms
  528.   dblScore = 25# * CDbl(nVisited) / CDbl(nRooms) + 75# * CDbl(nTreasuresRecovered) / CDbl(nTreasures) + 45# * CDbl(nTreasuresCarried) / CDbl(nTreasures)
  529.   If nVisited > 5 * nRooms Then
  530.     dblScore = dblScore - CDbl(nVisited) / (5# * CDbl(nRooms))
  531.     If dblScore < 0# Then
  532.       dblScore = 0#
  533.     End If
  534.   End If
  535.   nScore = Int(dblScore)
  536.   txtScore.Text = nScore
  537.   txtMaxScore.Text = 100
  538.   txtLocation.Text = strDescription(nRoom1) & strTreasures
  539.   If strTreasures = "" Then
  540.     pbCarry.Enabled = False
  541.   Else
  542.     pbCarry.Enabled = True
  543.   End If
  544.   If ((nRoom1 = 0) And (bTreasureCarried)) Then
  545.     pbDrop.Enabled = True
  546.   Else
  547.     pbDrop.Enabled = False
  548.   End If
  549.   If bConnected(nRoom1, 0, 0) Then
  550.     pbNorth.Enabled = True
  551.   Else
  552.     pbNorth.Enabled = False
  553.   End If
  554.   If bConnected(nRoom1, 0, 1) Then
  555.     pbSouth.Enabled = True
  556.   Else
  557.     pbSouth.Enabled = False
  558.   End If
  559.   If bConnected(nRoom1, 1, 0) Then
  560.     pbEast.Enabled = True
  561.   Else
  562.     pbEast.Enabled = False
  563.   End If
  564.   If bConnected(nRoom1, 1, 1) Then
  565.     pbWest.Enabled = True
  566.   Else
  567.     pbWest.Enabled = False
  568.   End If
  569.   If bConnected(nRoom1, 2, 0) Then
  570.     pbUp.Enabled = True
  571.   Else
  572.     pbUp.Enabled = False
  573.   End If
  574.   If bConnected(nRoom1, 2, 1) Then
  575.     pbDown.Enabled = True
  576.   Else
  577.     pbDown.Enabled = False
  578.   End If
  579.   If bConnected(nRoom1, 3, 0) Then
  580.     pbForward.Enabled = True
  581.   Else
  582.     pbForward.Enabled = False
  583.   End If
  584.   If bConnected(nRoom1, 3, 1) Then
  585.     pbBackward.Enabled = True
  586.   Else
  587.     pbBackward.Enabled = False
  588.   End If
  589. End Sub
  590. Private Sub Form_Load()
  591.   Dim strLine As String
  592.   Dim strProgramPath As String
  593.   MousePointer = 11
  594.   strWayOut = ""
  595.   Randomize nGame
  596.   strProgramPath = GetProgramPath()
  597.   Open strProgramPath & "treasure.dat" For Input As 1
  598.   Input #1, nTreasures
  599.   ReDim strTreasure(nTreasures)
  600.   ReDim strGuard(nTreasures)
  601.   ReDim nGuardRoom(nTreasures)
  602.   ReDim nTreasureRoom(nTreasures)
  603.   ReDim nWeaponRoom(nTreasures)
  604.   ReDim strWeapon(nTreasures)
  605.   nTreasure1 = 0
  606.   Do While nTreasure1 < nTreasures
  607.     Line Input #1, strTreasure(nTreasure1)
  608.     Line Input #1, strGuard(nTreasure1)
  609.     Line Input #1, strWeapon(nTreasure1)
  610.     nTreasure1 = nTreasure1 + 1
  611.   Loop
  612.   Close 1
  613.   Open strProgramPath & "descript.dat" For Input As 1
  614.   Input #1, nRooms
  615.   ReDim strDescription(nRooms)
  616.   ReDim bVisited(nRooms)
  617.   ReDim bConnected(nRooms, 4, 2)
  618.   ReDim bRoomUsed(nRooms)
  619.   nRoom1 = 0
  620.   Do While nRoom1 < nRooms
  621.     Line Input #1, strLine
  622.     strDescription(nRoom1) = "You're in " & strLine
  623.     bVisited(nRoom1) = False
  624.     nDimension1 = 0
  625.     Do While nDimension1 < nDimensions
  626.       nDirection1 = 0
  627.       Do While nDirection1 < 2
  628.         bConnected(nRoom1, nDimension1, nDirection1) = False
  629.         nDirection1 = nDirection1 + 1
  630.       Loop
  631.       nDimension1 = nDimension1 + 1
  632.     Loop
  633.     nRoom1 = nRoom1 + 1
  634.   Loop
  635.   Close 1
  636.   nMaxWidth = 1 + Int(CDbl(2 * nRooms) ^ (1# / CDbl(nDimensions)))
  637.   bWidthsFound = False
  638.   Do While Not bWidthsFound
  639.     nDimension1 = 0
  640.     nVolume = 1
  641.     Do While nDimension1 < nDimensions
  642.       nWidth(nDimension1) = nMaxWidth - Int(2# * Rnd)
  643.       nVolume = nVolume * nWidth(nDimension1)
  644.       nDimension1 = nDimension1 + 1
  645.     Loop
  646.     If nVolume > nRooms Then
  647.       bWidthsFound = True
  648.     End If
  649.   Loop
  650.   nDimension1 = nDimensions
  651.   Do While nDimension1 < 4
  652.     nWidth(nDimension1) = 1
  653.     nDimension1 = nDimension1 + 1
  654.   Loop
  655.   nRoom1 = 1
  656.   Do While nRoom1 < nRooms
  657.     nRoom2 = 1 + Int(CDbl(nRooms - 1) * Rnd)
  658.     strLine = strDescription(nRoom1)
  659.     strDescription(nRoom1) = strDescription(nRoom2)
  660.     strDescription(nRoom2) = strLine
  661.     nRoom1 = nRoom1 + 1
  662.   Loop
  663.   nXCoordinate = 0
  664.   Do While nXCoordinate < nWidth(0)
  665.     nYCoordinate = 0
  666.     Do While nYCoordinate < nWidth(1)
  667.       nZCoordinate = 0
  668.       Do While nZCoordinate < nWidth(2)
  669.         nTCoordinate = 0
  670.         Do While nTCoordinate < nWidth(3)
  671.           nCell(nXCoordinate, nYCoordinate, nZCoordinate, nTCoordinate) = -1
  672.           nTCoordinate = nTCoordinate + 1
  673.         Loop
  674.         nZCoordinate = nZCoordinate + 1
  675.       Loop
  676.       nYCoordinate = nYCoordinate + 1
  677.     Loop
  678.     nXCoordinate = nXCoordinate + 1
  679.   Loop
  680.   nXCoordinate = 0
  681.   nYCoordinate = 0
  682.   nZCoordinate = 0
  683.   nTCoordinate = 0
  684.   nCoordinate(0) = nXCoordinate
  685.   nCoordinate(1) = nYCoordinate
  686.   nCoordinate(2) = nZCoordinate
  687.   nCoordinate(3) = nTCoordinate
  688.   nRoom1 = 0
  689.   nRoom2 = 0
  690.   nCell(0, 0, 0, 0) = 0
  691.   Do While nRoom1 < (nRooms - 1)
  692.     bDirectionFound = False
  693.     Do While Not bDirectionFound
  694.       nDirection1 = Int(2# * Rnd)
  695.       nDimension1 = Int(CDbl(nDimensions) * Rnd)
  696.       If bEuclidean Then
  697.         If nCoordinate(nDimension1) + 2 * nDirection1 - 1 >= 0 Then
  698.           If nCoordinate(nDimension1) + 2 * nDirection1 - 1 < nWidth(nDimension1) Then
  699.             bDirectionFound = True
  700.           End If
  701.         End If
  702.       Else
  703.         bDirectionFound = True
  704.       End If
  705.     Loop
  706.     bConnected(nRoom2, nDimension1, nDirection1) = True
  707.     nCoordinateNext(0) = nCoordinate(0)
  708.     nCoordinateNext(1) = nCoordinate(1)
  709.     nCoordinateNext(2) = nCoordinate(2)
  710.     nCoordinateNext(3) = nCoordinate(3)
  711.     nCoordinateNext(nDimension1) = nCoordinate(nDimension1) + 2 * nDirection1 - 1
  712.     If (Not bEuclidean) Then
  713.       If nCoordinateNext(nDimension1) < 0 Then
  714.         nDimension2 = 0
  715.         Do While nDimension2 < nDimensions
  716.           nCoordinateNext(nDimension2) = nWidth(nDimension2) - nCoordinateNext(nDimension2) - 1
  717.           nDimension2 = nDimension2 + 1
  718.         Loop
  719.         nCoordinateNext(nDimension1) = nWidth(nDimension1) - 1
  720.       Else
  721.         If nCoordinateNext(nDimension1) >= nWidth(nDimension1) Then
  722.           nDimension2 = 0
  723.           Do While nDimension2 < nDimensions
  724.             nCoordinateNext(nDimension2) = nWidth(nDimension2) - nCoordinateNext(nDimension2) - 1
  725.             nDimension2 = nDimension2 + 1
  726.           Loop
  727.           nCoordinateNext(nDimension1) = 0
  728.         End If
  729.       End If
  730.     End If
  731.     If nCell(nCoordinateNext(0), nCoordinateNext(1), nCoordinateNext(2), nCoordinateNext(3)) < 0 Then
  732.       nRoom1 = nRoom1 + 1
  733.       nCell(nCoordinateNext(0), nCoordinateNext(1), nCoordinateNext(2), nCoordinateNext(3)) = nRoom1
  734.     End If
  735.     nRoom2 = nCell(nCoordinateNext(0), nCoordinateNext(1), nCoordinateNext(2), nCoordinateNext(3))
  736.     bConnected(nRoom2, nDimension1, 1 - nDirection1) = True
  737.     nCoordinate(0) = nCoordinateNext(0)
  738.     nCoordinate(1) = nCoordinateNext(1)
  739.     nCoordinate(2) = nCoordinateNext(2)
  740.     nCoordinate(3) = nCoordinateNext(3)
  741.   Loop
  742.   nTreasure1 = 0
  743.   Do While nTreasure1 < nTreasures
  744.     nTreasureRoom(nTreasure1) = 1 + Int(CDbl(nRooms - 1) * Rnd)
  745.     nGuardRoom(nTreasure1) = nTreasureRoom(nTreasure1)
  746.     bWeaponRoomFound = False
  747.     Do While Not bWeaponRoomFound
  748.       nWeaponRoom(nTreasure1) = 1 + Int(CDbl(nRooms - 1) * Rnd)
  749.       If nWeaponRoom(nTreasure1) <> nTreasureRoom(nTreasure1) Then
  750.         bWeaponRoomFound = True
  751.       End If
  752.     Loop
  753.     nTreasure1 = nTreasure1 + 1
  754.   Loop
  755.   bInitialized = True
  756.   GameUpdate
  757.   MousePointer = 0
  758. End Sub
  759. Private Sub Form_Unload(Cancel As Integer)
  760.   Dim Response As Long
  761.   If bInitialized Then
  762.     If nScore < 20 Then
  763.       Response = MsgBox("Your score ranks you as a beginner.", vbOKOnly, "You scored " & CStr(nScore) & " out of 100 points.")
  764.     Else
  765.       If nScore < 40 Then
  766.         Response = MsgBox("Your score ranks you as a novice adventurer.", vbOKOnly, "You scored " & CStr(nScore) & " out of 100 points.")
  767.       Else
  768.         If nScore < 60 Then
  769.           Response = MsgBox("Your score ranks you as a seasoned explorer.", vbOKOnly, "You scored " & CStr(nScore) & " out of 100 points.")
  770.         Else
  771.           If nScore < 80 Then
  772.             Response = MsgBox("Your score ranks you as a grissly old prospector.", vbOKOnly, "You scored " & CStr(nScore) & " out of 100 points.")
  773.           Else
  774.             Response = MsgBox("Your score ranks you as an expert treasure hunter;  there is no higher rating.", vbOKOnly, "You scored " & CStr(nScore) & " out of 100 points.")
  775.           End If
  776.         End If
  777.       End If
  778.     End If
  779.   End If
  780. End Sub
  781. Private Sub pbAbout_Click()
  782.   Dim Response As Long
  783.   Response = MsgBox("Adventures in 4 Dimensions" + Chr(13) + Chr(13) + "Copyright " + Chr(169) + " 1997 James L. Dean (csvcjld@nomvs.lsumc.edu)" + Chr(13) + Chr(13) + "This application may be distributed or used without payment to James L. Dean." + Chr(13) + Chr(13) + "As per Microsoft's license for Visual Basic 4.0, the end-user may not distribute the components having names starting with other than " _
  784. + Chr(34) + "treasure" + Chr(34) + "," + Chr(34) + "init" + Chr(34) + "," + Chr(34) + "game" + Chr(34) + "," + Chr(34) + "descript" + Chr(34) + ", or " + Chr(34) + "file_id" + Chr(34) + ".", vbOKOnly, "About Adventures in 4 Dimensions Release 4.4")
  785. End Sub
  786. Private Sub pbBackward_Click()
  787.   nMoves = nMoves + 1
  788.   nTCoordinate = nTCoordinate + 1
  789.   GameUpdate
  790. End Sub
  791. Private Sub pbCarry_Click()
  792.   Dim Response As Long
  793.   nTreasure1 = 0
  794.   Do While nTreasure1 < nTreasures
  795.     If nWeaponRoom(nTreasure1) = nRoom1 Then
  796.       nWeaponRoom(nTreasure1) = -1
  797.     End If
  798.     nTreasure1 = nTreasure1 + 1
  799.   Loop
  800.   nTreasure1 = 0
  801.   Do While nTreasure1 < nTreasures
  802.     If nTreasureRoom(nTreasure1) = nRoom1 Then
  803.       If nWeaponRoom(nTreasure1) < 0 Then
  804.         nTreasureRoom(nTreasure1) = -1
  805.         nTreasuresRecovered = nTreasuresRecovered + 1
  806.         If nGuardRoom(nTreasure1) = nRoom1 Then
  807.           nGuardRoom(nTreasure1) = -1
  808.           nWeaponRoom(nTreasure1) = -2
  809.           Response = MsgBox("You're " & strWeapon(nTreasure1) & " overcomes the " & strGuard(nTreasure1) & ".", vbOKOnly, "Way to go!")
  810.         End If
  811.       Else
  812.         Response = MsgBox("You carry nothing to overcome the " & strGuard(nTreasure1) & ".", vbOKOnly, "Whoops!")
  813.       End If
  814.     End If
  815.     If nWeaponRoom(nTreasure1) = nRoom1 Then
  816.       nWeaponRoom(nTreasure1) = -1
  817.     End If
  818.     nTreasure1 = nTreasure1 + 1
  819.   Loop
  820.   GameUpdate
  821. End Sub
  822. Private Sub pbDown_Click()
  823.   nMoves = nMoves + 1
  824.   nZCoordinate = nZCoordinate + 1
  825.   GameUpdate
  826. End Sub
  827. Private Sub pbDrop_Click()
  828.   nTreasure1 = 0
  829.   Do While nTreasure1 < nTreasures
  830.     If nTreasureRoom(nTreasure1) = -1 Then
  831.       nTreasureRoom(nTreasure1) = 0
  832.     End If
  833.     nTreasure1 = nTreasure1 + 1
  834.   Loop
  835.   GameUpdate
  836. End Sub
  837. Private Sub pbEast_Click()
  838.   nMoves = nMoves + 1
  839.   nYCoordinate = nYCoordinate - 1
  840.   GameUpdate
  841. End Sub
  842. Private Sub pbForward_Click()
  843.   nMoves = nMoves + 1
  844.   nTCoordinate = nTCoordinate - 1
  845.   GameUpdate
  846. End Sub
  847. Private Sub pbNorth_Click()
  848.   nMoves = nMoves + 1
  849.   nXCoordinate = nXCoordinate - 1
  850.   GameUpdate
  851. End Sub
  852. Private Sub pbSouth_Click()
  853.   nMoves = nMoves + 1
  854.   nXCoordinate = nXCoordinate + 1
  855.   GameUpdate
  856. End Sub
  857. Private Sub pbUp_Click()
  858.   nMoves = nMoves + 1
  859.   nZCoordinate = nZCoordinate - 1
  860.   GameUpdate
  861. End Sub
  862. Private Sub pbWayOut_Click()
  863.   Dim Response As Long
  864.   bPathFound = False
  865.   If ((bTreasureCarried) And (nRoom1 <> 0)) Then
  866.     nCoordinate(0) = nXCoordinate
  867.     nCoordinate(1) = nYCoordinate
  868.     nCoordinate(2) = nZCoordinate
  869.     nCoordinate(3) = nTCoordinate
  870.     nWayOutHead = 0
  871.     nRoom2 = 0
  872.     Do While nRoom2 < nRooms
  873.       bRoomUsed(nRoom2) = False
  874.       nRoom2 = nRoom2 + 1
  875.     Loop
  876.     bRoomUsed(nRoom1) = True
  877.     nDirectionsUsed(nWayOutHead) = 0
  878.     nDirectionsPossible = 2 * nDimensions
  879.     nDimension1 = 0
  880.     Do While nDimension1 < nDimensions
  881.       nDirection1 = 0
  882.       Do While nDirection1 < 2
  883.         bDirectionUsed(nWayOutHead, nDimension1, nDirection1) = False
  884.         nDirection1 = nDirection1 + 1
  885.       Loop
  886.       nDimension1 = nDimension1 + 1
  887.     Loop
  888.     strWayOut = ""
  889.     nRoom2 = nRoom1
  890.     nTrial = 0
  891.     MousePointer = 11
  892.     Do While (nTrial < 500) And (nRoom2 <> 0) And (nWayOutHead < 255)
  893.       nTrial = nTrial + 1
  894.       bDirectionFound = False
  895.       Do While (Not bDirectionFound) And (nDirectionsUsed(nWayOutHead) < nDirectionsPossible)
  896.         nDirection1 = Int(2# * Rnd)
  897.         nDimension1 = Int(CDbl(nDimensions) * Rnd)
  898.         If (Not bDirectionUsed(nWayOutHead, nDimension1, nDirection1)) Then
  899.           bDirectionUsed(nWayOutHead, nDimension1, nDirection1) = True
  900.           nDirectionsUsed(nWayOutHead) = nDirectionsUsed(nWayOutHead) + 1
  901.           If bConnected(nRoom2, nDimension1, nDirection1) Then
  902.             nCoordinateNext(0) = nCoordinate(0)
  903.             nCoordinateNext(1) = nCoordinate(1)
  904.             nCoordinateNext(2) = nCoordinate(2)
  905.             nCoordinateNext(3) = nCoordinate(3)
  906.             nCoordinateNext(nDimension1) = nCoordinate(nDimension1) + 2 * nDirection1 - 1
  907.             If (Not bEuclidean) Then
  908.               If nCoordinateNext(nDimension1) < 0 Then
  909.                 nDimension2 = 0
  910.                 Do While nDimension2 < nDimensions
  911.                   nCoordinateNext(nDimension2) = nWidth(nDimension2) - nCoordinateNext(nDimension2) - 1
  912.                   nDimension2 = nDimension2 + 1
  913.                 Loop
  914.                 nCoordinateNext(nDimension1) = nWidth(nDimension1) - 1
  915.               Else
  916.                 If nCoordinateNext(nDimension1) >= nWidth(nDimension1) Then
  917.                   nDimension2 = 0
  918.                   Do While nDimension2 < nDimensions
  919.                     nCoordinateNext(nDimension2) = nWidth(nDimension2) - nCoordinateNext(nDimension2) - 1
  920.                     nDimension2 = nDimension2 + 1
  921.                   Loop
  922.                   nCoordinateNext(nDimension1) = 0
  923.                 End If
  924.               End If
  925.             End If
  926.             If (Not bRoomUsed(nCell(nCoordinateNext(0), nCoordinateNext(1), nCoordinateNext(2), nCoordinateNext(3)))) Then
  927.               bDirectionFound = True
  928.             End If
  929.           End If
  930.         End If
  931.       Loop
  932.       If bDirectionFound Then
  933.         nRoom2 = nCell(nCoordinateNext(0), nCoordinateNext(1), nCoordinateNext(2), nCoordinateNext(3))
  934.         nWayOutHead = nWayOutHead + 1
  935.         bRoomUsed(nRoom2) = True
  936.         nDirectionsUsed(nWayOutHead) = 0
  937.         nDimension2 = 0
  938.         Do While nDimension2 < nDimensions
  939.           nDirection2 = 0
  940.           Do While nDirection2 < 2
  941.             bDirectionUsed(nWayOutHead, nDimension2, nDirection2) = False
  942.             nDirection2 = nDirection2 + 1
  943.           Loop
  944.           nDimension2 = nDimension2 + 1
  945.         Loop
  946.         nWayOutDimension(nWayOutHead) = nDimension1
  947.         nWayOutDirection(nWayOutHead) = 1 - nDirection1
  948.         Select Case nDimension1
  949.           Case 0
  950.             If nDirection1 = 0 Then
  951.               strWayOut = strWayOut & "N"
  952.             Else
  953.               strWayOut = strWayOut & "S"
  954.             End If
  955.           Case 1
  956.             If nDirection1 = 0 Then
  957.               strWayOut = strWayOut & "E"
  958.             Else
  959.               strWayOut = strWayOut & "W"
  960.             End If
  961.           Case 2
  962.             If nDirection1 = 0 Then
  963.               strWayOut = strWayOut & "U"
  964.             Else
  965.               strWayOut = strWayOut & "D"
  966.             End If
  967.           Case Else
  968.             If nDirection1 = 0 Then
  969.               strWayOut = strWayOut & "F"
  970.             Else
  971.               strWayOut = strWayOut & "B"
  972.             End If
  973.         End Select
  974.       Else
  975.         nDirection1 = nWayOutDirection(nWayOutHead)
  976.         nDimension1 = nWayOutDimension(nWayOutHead)
  977.         nCoordinateNext(0) = nCoordinate(0)
  978.         nCoordinateNext(1) = nCoordinate(1)
  979.         nCoordinateNext(2) = nCoordinate(2)
  980.         nCoordinateNext(3) = nCoordinate(3)
  981.         nCoordinateNext(nDimension1) = nCoordinateNext(nDimension1) + 2 * nDirection1 - 1
  982.         If (Not bEuclidean) Then
  983.           If nCoordinateNext(nDimension1) < 0 Then
  984.             nDimension2 = 0
  985.             Do While nDimension2 < nDimensions
  986.               nCoordinateNext(nDimension2) = nWidth(nDimension2) - nCoordinateNext(nDimension2) - 1
  987.               nDimension2 = nDimension2 + 1
  988.             Loop
  989.             nCoordinateNext(nDimension1) = nWidth(nDimension1) - 1
  990.           Else
  991.             If nCoordinateNext(nDimension1) >= nWidth(nDimension1) Then
  992.               nDimension2 = 0
  993.               Do While nDimension2 < nDimensions
  994.                 nCoordinateNext(nDimension2) = nWidth(nDimension2) - nCoordinateNext(nDimension2) - 1
  995.                 nDimension2 = nDimension2 + 1
  996.               Loop
  997.               nCoordinateNext(nDimension1) = 0
  998.             End If
  999.           End If
  1000.         End If
  1001.         nRoom2 = nCell(nCoordinateNext(0), nCoordinateNext(1), nCoordinateNext(2), nCoordinateNext(3))
  1002.         nWayOutHead = nWayOutHead - 1
  1003.         If Len(strWayOut) > 1 Then
  1004.           strWayOut = Left(strWayOut, Len(strWayOut) - 1)
  1005.         Else
  1006.           strWayOut = ""
  1007.         End If
  1008.       End If
  1009.       nCoordinate(0) = nCoordinateNext(0)
  1010.       nCoordinate(1) = nCoordinateNext(1)
  1011.       nCoordinate(2) = nCoordinateNext(2)
  1012.       nCoordinate(3) = nCoordinateNext(3)
  1013.     Loop
  1014.     MousePointer = 0
  1015.     If nRoom2 = 0 Then
  1016.       bPathFound = True
  1017.     End If
  1018.   End If
  1019.   If bPathFound Then
  1020.     nTreasure1 = 0
  1021.     nRoom2 = 0
  1022.     Do While (nTreasure1 < nTreasures) And (nRoom2 >= 0)
  1023.       nRoom2 = nTreasureRoom(nTreasure1)
  1024.       If nRoom2 >= 0 Then
  1025.         nTreasure1 = nTreasure1 + 1
  1026.       End If
  1027.     Loop
  1028.     nRoom2 = nRoom1
  1029.     Do While nRoom1 = nRoom2
  1030.       nRoom2 = 1 + Int(CDbl(nRooms - 1) * Rnd)
  1031.     Loop
  1032.     nTreasureRoom(nTreasure1) = nRoom2
  1033.     Response = MsgBox("As he leaves,  he shouts the letters, '" & strWayOut & "'.", vbOKOnly, "The pirate takes one of your treasures.")
  1034.     GameUpdate
  1035.   Else
  1036.     Response = MsgBox("Try again later.", vbOKOnly, "Nothing happens.")
  1037.   End If
  1038. End Sub
  1039. Private Sub pbWest_Click()
  1040.   nMoves = nMoves + 1
  1041.   nYCoordinate = nYCoordinate + 1
  1042.   GameUpdate
  1043. End Sub
  1044.